package com.shqcjd.generalplatformprojectclient.util;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * autour: lqm
 * desc: SharePreference的封装
 */

public class PrefUtils {

    public static final String PREF_NAME = "config";
    public static final String COMPANY_NAME = "cname";//公司名称
    public static final String COMPANY_ID = "cid";//公司id
    public static final String USER_PHONE = "phone";//用户手机号
    public static final String USER_ROLE_ID = "rid";//用户角色id
    public static final String USER_USER_ID = "uid";//用户id
    public static final String HISTORY_EQUIPMENT_LIST = "history_eq";//首页的设备搜索历史
    public static final String HISTORY_EQUIPMENT_TYPE_LIST = "history_eq_type";//首页的设备类型搜索历史
    public static final String TOKEN = "token";//token
    public static final String LAUNCH_REMOTE_BEAN = "launchRemoteBean";//发起远程指导的实体
    public static final String USE_GLASS = "USE_GLASS";//使用眼镜


    public static boolean getBoolean(Context ctx, String key,
                                     boolean defaultValue) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME,
                Context.MODE_PRIVATE);
        return sp.getBoolean(key, defaultValue);
    }

    public static void setBoolean(Context ctx, String key, boolean value) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME,
                Context.MODE_PRIVATE);
        sp.edit().putBoolean(key, value).commit();
    }

    public static String getString(Context ctx, String key, String defaultValue) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME,
                Context.MODE_PRIVATE);
        return sp.getString(key, defaultValue);
    }

    public static void setString(Context ctx, String key, String value) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME,
                Context.MODE_PRIVATE);
        sp.edit().putString(key, value).commit();
    }

    public static int getInt(Context ctx, String key, int defaultValue) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME,
                Context.MODE_PRIVATE);
        return sp.getInt(key, defaultValue);
    }

    public static void setInt(Context ctx, String key, int value) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME,
                Context.MODE_PRIVATE);
        sp.edit().putInt(key, value).commit();
    }

    public static void clearData(Context ctx, String key) {
        SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        sp.edit().remove(key).clear().commit();
    }
}
